type UserTextEvent = { type:"TextEvent", value: string, target: HTMLInputElement };
type UserMouseEvent = { type:"MouseEvent", value: number, target: HTMLButtonElement };

type UserEvent = UserTextEvent | UserMouseEvent;

/* type UserEvent = {
  value: string | number;
  target: HTMLInputElement | HTMLButtonElement;
};

value: string ---> target: HTMLInputElement | HTMLButtonElement;
value: number ---> target: HTMLInputElement | HTMLButtonElement; */

function handle(event: UserEvent) { 
  if (event.type === "TextEvent") { 
    console.log(event.value);
    console.log(event.target)
  }
  else {
    console.log(event.value);
    console.log(event.target)
  }
}
handle({ type: "MouseEvent", value: 1, target: document.getElementsByTagName("button")[0] })

// 比如要定义一个类型别名 Shape，如果有circle，就应该有radius属性，如果有rect，就应该有width和height属性
// type Shape = {
//   kind: "circle" | "rect";
//   radius?: number;
//   width?: number;
//   height?: number;
// }

type Circle = {
  kind: "circle";
  radius: number;
}

type Rect = {
  kind: "rect";
  width: number;
  height: number;
}

type Shape = Circle | Rect;

function area(s: Shape) {
  if (s.kind === "circle") {
    return Math.PI * s.radius ** 2;
  } else {
    return s.width * s.height;
  }
}

